/**
 * 
 */
package neptune.web.client.view;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * @author Roberto Bifulco [info@robertobifulco.it, robertobifulco.it]
 * 
 */
public class ConsoleManager {

	private static ArrayList<HasConsole> consoles = new ArrayList<HasConsole>(0);
	private static boolean debug = true;

	public static void addConsoleMessage(String message, boolean isError) {
		for (Iterator<HasConsole> consoleIterator = consoles.iterator(); consoleIterator
				.hasNext();) {
			HasConsole console = (HasConsole) consoleIterator.next();
			console.addConsoleMessage(message, isError);
		}
	}

	public static void addConsoleDebugMessage(String message, boolean isError) {
		if (debug)
			for (Iterator<HasConsole> consoleIterator = consoles.iterator(); consoleIterator
					.hasNext();) {
				HasConsole console = (HasConsole) consoleIterator.next();
				console.addConsoleMessage(message, isError);
			}
	}

	public static void addConsole(HasConsole console) {
		consoles.add(console);
	}

	public static void removeConsole(HasConsole console) {
		consoles.remove(console);
	}

	public static boolean isDebug() {
		return debug;
	}

	public static void setDebug(boolean debug) {
		ConsoleManager.debug = debug;
	}
}
